package com.lame.sbconstant.product;

import com.lame.detect.vo.ClassMeta;
import com.lame.detect.vo.FileType;
import com.lame.sbconstant.product.strategy.ClassInnerConstantStrategy;
import com.lame.sbconstant.product.strategy.DfConstantStrategy;
import com.lame.sbconstant.product.strategy.DfControllerStrategy;
import com.lame.sbconstant.product.strategy.DfDaoStrategy;
import com.lame.sbconstant.product.strategy.DfServiceImplStrategy;
import com.lame.sbconstant.product.strategy.DfServiceStrategy;
import com.lame.sbconstant.product.vo.ProductDesc;
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.tree.ParseTree;

import javax.annotation.Nonnull;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 常量工厂
 **/
public class ProductFactory {

    public static ProductDirect getDirector(FileType fileType) {
        ProductDirect productContext = null;
        switch (fileType) {
            case CONTROLLER:
                productContext = new ProductDirect(new DfControllerStrategy());
                break;
            case CONSTANT:
                productContext = new ProductDirect(new DfConstantStrategy());
                break;
            case DAO:
                productContext = new ProductDirect(new DfDaoStrategy());
                break;
            case SERVICE:
                productContext = new ProductDirect(new DfServiceStrategy());
                break;
            case SERVICEIMPL:
                productContext = new ProductDirect(new DfServiceImplStrategy());
                break;
            case COMMON:
            default:
                productContext = new ProductDirect(new ClassInnerConstantStrategy());
                break;
        }
        return productContext;
    }


    public static List<ProductDesc> product(@Nonnull List<FileType> fileTypes,
                                            @Nonnull Parser parser,
                                            @Nonnull ParseTree parseTree,
                                            @Nonnull ClassMeta classMeta
    ) {
        return fileTypes.stream().map(it -> {
            final ProductDirect direct = getDirector(it);
            final ProductDesc productDesc = direct.productDesc(parser, parseTree, classMeta);
            return productDesc;
        }).collect(Collectors.toList());
    }
}
